export function useUi() {
    const confirm = (options: {
        title: string,
        content: string,
        cancelText?: string,
        confirmText?: string,
    }) => {
        return new Promise<boolean>((resolve) => {
            uni.showModal({
                title: options.title,
                content: options.content,
                showCancel: true,
                mask: true,
                cancelText: options.cancelText || '取消',
                confirmText: options.confirmText || '确认',
                success: (res) => {
                    if (res.confirm) {
                        resolve(true);
                    } else if (res.cancel) {
                        resolve(false);
                    }
                },
            });
        });
    };

    const alert = (options: {
        title: string,
        content: string,
        confirmText?: string,
    }) => {
        return new Promise<boolean>((resolve) => {
            uni.showModal({
                title: options.title,
                content: options.content,
                showCancel: false,
                mask: true,
                confirmText: options.confirmText || '确认',
                success: (res) => {
                    if (res.confirm) {
                        resolve(true);
                    }
                },
            });
        });
    };

    return {
        confirm,
        alert,
    }
}
